﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Zhongchouwwwww.Models;

namespace Zhongchouwwwww.webform
{
    public partial class user_login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var result = Request.QueryString["id"];
                if (result == "true")
                {
                    Response.Write(@"<script language >alert('注册成功！')<" + "/script>");
                }
                else
                {
                    Response.Write(@"<script language >alert('请先登录！')<" + "/script>");
                }

            }

        }

        protected void btn_login_Click(object sender, EventArgs e)
        {
            using (ZhongchouDBEntities DB = new ZhongchouDBEntities())
            {
                var userlogn = DB.Userinfo.FirstOrDefault(u => u.userphone == username.Text && u.userpwd == password.Text && u.userstate=="正常");
                if (userlogn == null)
                {
                    Response.Write(@"<script language>alert('账号密码不正确或账号已被封禁')</script>");
                }
                else
                {
                    //Response.Cookies.Add(new HttpCookie("username", userlogn.usernikename) { Expires = DateTime.Now.AddMinutes(30) });
                    //Response.Cookies.Add(new HttpCookie("userid", userlogn.userid.ToString())
                    //{ Expires = DateTime.Now.AddMinutes(30) });
                    Config.Config.ThisUser.UserId = userlogn.userid;
                    Config.Config.ThisUser.UserName = userlogn.usernikename;
                    Config.Config.ThisUser.UserPhone = userlogn.userphone;
                    Config.Config.ThisUser.UserSex = userlogn.sex;
                    Config.Config.ThisUser.UserImg = userlogn.imgurl;
                    Config.Config.ThisUser.UserRegistertime = userlogn.registertime;
                    Config.Config.ThisUser.UserNikenametime = userlogn.nikenametime;
                    Config.Config.ThisUser.Userdesc = userlogn.userdesc;
                    Config.Config.ThisUser.UserWebsite = userlogn.website;
                    Response.Redirect($"Index1.aspx");
                    
                }
            }
        }
    }
}